package com.trans.utils;


import java.math.BigDecimal;
import java.util.*;

/**
 * @Author xwduo
 * @Description //TODO
 * @Date 2023-05-29 15:12
 */
public class TypeUtils {

    /**
     * 静态数据包-该包不需要深度遍历
     */
    private static final List<Class> STATIC_TYPE = new ArrayList<>(
            Arrays.asList(
                    Integer.class,BigDecimal.class,Double.class,Long.class,Short.class,Float.class,
                    String.class,Character.class,Byte.class,Date.class,Boolean.class
            ));
    public static final List<String> PACK_NAMES = new ArrayList<>();

    /**
     * @Description: 判断是否为基础类（整型、浮点类型等），可跳过翻译
     * @Author: xwduo
     * @Date: 2022-10-28 17:16
     * @param： data:
     * * @return boolean
     */
    public static boolean isCustomClass(Object data) {
        if(null == data){
            return false;
        }
        return isCustomClass(data.getClass());
    }

    public static boolean isCustomClass(Class<?> clazz) {
        if (clazz.isPrimitive() || STATIC_TYPE.contains(clazz)) {
            return false;
        }
        if(!PACK_NAMES.isEmpty()){
            for (String packName : PACK_NAMES) {
                if(clazz.getPackage().getName().startsWith(packName)){
                    return true;
                }
            }
            return false;
        }
        return true;
    }


}
